/*
 * @Author: ZhanXie
 * @Date: 2019-11-27 10:08:35
 * @LastEditors: ZhanXie
 * @LastEditTime: 2019-12-03 18:56:27
 * @Description: user 控制层
 * @FilePath: /node-demo/blog-origin/src/controller/user.js
 */
const { exec, escape } = require('../db/mysql')
const { genPassWord } = require('../util/cryp')

const login = (username, password) => {
  username = escape(username)
  
  
  password = genPassWord(password) // 生成加密密码
  password = escape(password) // 防止 sql 注入

  const sql = `select username, realname from users where username=${username} and password=${password}`

  return exec(sql).then(rows => {
    return rows[0] || {}
  })
}

module.exports = {
  login
}